#include "Object.hpp"

static DBServer::Base::Timer::Time t;

using namespace DBServer::Database;

const char* DBServer::Database::Object::object_name[5] = {
    "string_object",
    "hash_object",
    "list_object",
    "set_object",
    "zset_object"
};

Object::Object(int _object_type)
:   object_type(_object_type), 
    time(false),
    timer()
{}

std::string Object::get_type()
{
    return std::string(object_name[object_type]);
}

unsigned long long Object::get_expire()
{
    t.cur();
    t -= timer.get_time();
    return static_cast<unsigned long long>(t.get_time());
}

void Object::set_expire(unsigned long long _expire)
{
    time = true;
    timer.later(static_cast<long long>(_expire));
}

bool Object::timeout()
{
    return time && timer.is_timeout();
}